const Shape = require("./shape.js")
const Utils = require("./utils.js")
const {EN,ClassMapping,Letter} = require("./constant.js")
module.exports = class Point extends Shape{
	constructor($env,$event){
		super($env,$event)
		this.name = ClassMapping.point
		this.__letters = Letter.capital
		this.bind();
	}
	bind(){
		this.baseContext.canvas.addEventListener("click",(e)=>{
			if (!this.isActive) return;
			var pos = {
					x : e.pageX,
			        y : e.pageY
			}
			this.draw(this.cvsEvtPos(pos,this.cvs))
		})
	}
	draw(pos){
		let isInPath = this.isInPath(pos.x,pos.y);
		if(isInPath.length)return;
		let p = Utils.assign(this.__setting,pos);
		let ctx = this.ctx;
		p.fillStyle = ctx.fillStyle;

		let index = this.$env[this.name];
		p.text = this.generateLabel();
		this.rePaint(p)
		this.__steps=p
		this.emit(EN.update_state,this,p)
	}
	rePaint(p,context){
		let ctx = context||this.ctx;
		ctx.fillStyle = p.fillStyle
		this.drawPoint(p,ctx)
		ctx.font=this.$env.font;
		ctx.fillText(p.text,p.x-5,p.y-10);

	}
}
